package com.gao.controller;

import com.gao.dto.OrderDTO;
import com.gao.entity.Order;
import com.gao.service.OrderService;
import com.gao.util.ResultVO;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author gao
 * @time 2022/11/25 11:26:47
 */
@RestController
@RequiredArgsConstructor
public class OrderController {

    @NonNull
    private OrderService orderService;

    @RequestMapping("/orders/addOrder")
    public ResultVO addOrder(@RequestBody OrderDTO orderDTO) {
        orderService.addOrder(orderDTO.getProductIds(), orderDTO.getQuantities());
        return ResultVO.success("下单成功");
    }

    @RequestMapping("/orders/getOrder/{orderId}")
    public ResultVO getOrder(@PathVariable Integer orderId) {
        Order order = orderService.getOrderDetailByOrderId(orderId);
        return ResultVO.success("查询订单成功", order);
    }

}